﻿using System.Text.RegularExpressions;

namespace LiveHub.DataModels;

[Serializable]
public class GroupModel
{
    public string GroupId { get; set; } = "";

    public string Name { get; set; } = "";
    public List<UserModel> Users { get; set; } = [];
    public List<MessageModel> Messages { get; set; } = [];
}

[Serializable]
public partial class MessageModel
{
    public string MessageId { get; set; } = "";
    public string UserId { get; set; } = "";
    public UserModel User { get; set; } = new();
    public string Body { get; set; } = "";
    public string Time { get; init; } = DateTime.Now.ToString("g");

    public string[] GetAtUser() => AtRegex().Matches(Body).Select(x => x.Value).ToArray();

    [GeneratedRegex(@"@.*?\s")]
    private static partial Regex AtRegex();
}